<template>
	<view>
		
		<!-- 顶部导航栏 -->
		<head-custom  @searchBtn="searchBtn" />
		
		<!-- 暂无数据 -->
		<no-data v-if="noteListPage.sum && !noteList.length" />
		
		<!-- 笔记列表 -->
		<list-data :list="noteList" />
		
		<view style="padding-bottom: 20rpx;">
			<u-loadmore :status="list_status" />
		</view>
				
	</view>
</template>

<script>
	// 导入组件
	import headCustom from './components/head-custom'
	import noData from './components/no-data'
	import listData from './components/list-data'
	
	// 导入Api
	import { getNoteList } from '@/http/api'
	
	export default {
		// 注册组件
		components:{ headCustom , noData , listData },
		data() {
			return {
				// 笔记列表
				noteList:[]
			}
		},
		async onLoad() {
			await this.getNoteList()
			if(!this.userinfo.token)return this.pageGo('/pages/home/login')
		},
		onReachBottom() {
			this.getNoteList()
		},
		async onPullDownRefresh() {
			await this.getNoteList('',true)
			uni.stopPullDownRefresh();
		},
		methods: {
			// 获取笔记列表方法
			async getNoteList(key='',clear=false){
				if(clear){
					this.curPage = 1
					this.list_status = 'loadmore'
				}
				// 判断请求状态
				if(this.list_status!='loadmore')return false;
				// 修改请求状态
				this.list_status = 'loading';
				// 请求服务器
				let res = await getNoteList({page:this.curPage,key:key});
				if(res.code==1){
					// 返回笔记列表
					this.noteList = this.curPage==1 ? res.data.list : [...this.noteList,...res.data.list];
					// 返回笔记列表分页
					this.noteListPage = res.data.page
					this.getStatus(res)
				}else{
					this.list_status = 'none'
				}
			},
			// 搜索点击
			searchBtn(e){
				this.getNoteList(e,true)
			}
		}
	}
</script>

<style scoped lang="scss">
	
</style>
